import http from './index'

export default {
  // 请求示例
  /* getBanner() {
    return new Promise((resolve, reject) => {
      http('get', '/banner').then(
        (res) => {
          resolve(res)
        },
        (error) => {
          reject(error)
        }
      )
    })
  }, */
  // 获取所有用户
  getUser() {
    return new Promise((resolve, reject) => {
      http('get', '/backend/user').then(
        (res) => {
          resolve(res)
        },
        (error) => {
          reject(error)
        }
      )
    })
  },
  // 获取普通用户
  getNormal() {
    return new Promise((resolve, reject) => {
      http('get', '/backend/user/normal').then(
        (res) => {
          resolve(res)
        },
        (error) => {
          resolve(error)
        }
      )
    })
  },
  // 获取交管用户
  getTraffic() {
    return new Promise((resolve, reject) => {
      http('get', '/backend/user/traffic').then(
        (res) => {
          resolve(res)
        },
        (error) => {
          reject(error)
        }
      )
    })
  },
  // 搜索用户
  getSearchUser(val) {
    return new Promise((resolve, reject) => {
      http(
        'get',
        `/backend/user/search?username=${val.value}&type=${val.type}`
      ).then(
        (res) => {
          resolve(res)
        },
        (error) => {
          reject(error)
        }
      )
    })
  },
  // 改变当前状态
  putUserStatus(val) {
    return new Promise((resolve, reject) => {
      http('post', `/backend/user/status`, {
        status: val.checked,
        id: val.id,
      }).then(
        (res) => {
          resolve(res)
        },
        (error) => {
          reject(error)
        }
      )
    })
  },
  // 删除用户
  deleteUser(id) {
    return new Promise((resolve, reject) => {
      http('post', `/backend/user/delete?id=${id}`).then(
        (res) => {
          resolve(res)
        },
        (error) => {
          reject(error)
        }
      )
    })
  },
  // 改变用户等级
  /**
   *
   * @param {Object} val   {id:1,type:"traffic"|"normal"}
   */
  postChangeLevel(val) {
    return new Promise((resolve, reject) => {
      http('post', `/backend/user/changelevel`, {
        id: val.id,
        type: val.type,
      }).then(
        (res) => {
          resolve(res)
        },
        (error) => {
          reject(error)
        }
      )
    })
  },
  //修改用户
  /**
   *
   * @param {Object} val {username:admin,password:admin,id:1}
   */
  postChangeUser(val) {
    return new Promise((resolve, reject) => {
      http('post', '/backend/user/changeuser', val).then(
        (res) => {
          resolve(res)
        },
        (error) => {
          reject(error)
        }
      )
    })
  },
  // 删除选中
  postDelSelceted(val) {
    return new Promise((resolve, reject) => {
      http('post', '/backend/user/delselected', { val: val }).then(
        (res) => {
          resolve(res)
        },
        (error) => {
          reject(error)
        }
      )
    })
  },
  // 新增用户
  postAddUser(val) {
    return new Promise((resolve, reject) => {
      http('post', '/backend/user/adduser', val).then(
        (res) => {
          resolve(res)
        },
        (error) => {
          reject(error)
        }
      )
    })
  },
}
